package org.example.concurrent.atomic;

import java.util.concurrent.atomic.AtomicInteger;

public class AtomicIntegerTest2 {
    public static void main(String[] args) {
        // 声明一个AtomicInteger对象
        AtomicInteger num = new AtomicInteger(0);
        // 线程1
        new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                // num++
                num.incrementAndGet();
            }
        }).start();
        // 线程2
        new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                // num++
                num.incrementAndGet();
            }
        }).start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(num);

    }
}
